<?php

namespace app\common\model;

use think\Model;
use traits\model\SoftDelete;

class Content extends Model
{
    //软删除
    use SoftDelete;

    //校区添加
    public function content_add($data)
    {
       $validate = new \app\common\validate\Content();
       if (!$validate->check($data)){
            return $validate -> getError();
       }
       //获取地址经纬度
       $data['jwd'] = getAddress($data['address']);
       $result = $this -> allowField(true) -> save($data);
       if ($result){
            return 1;
       } else {
            return '添加失败！';
       }
    }

    //状态控制
    public function content_status($data)
    {
       $conInfo = $this -> find($data['id']);
       $conInfo -> status = $data['status']?0:1;
        $result = $conInfo -> save();
       if ($result) {
           return 1;
       } else {
           return '操作失败！';
       }
    }

    //编辑
    public function content_edit($data)
    {
        $validate = new \app\common\validate\Content();
        if (!$validate->check($data)){
            return $validate -> getError();
        }
        //获取地址经纬度
        $data['jwd'] = getAddress($data['address']);
        $con = $this -> find($data['id']);
        $con -> campus = $data['campus'];
        $con -> website = $data['website'];
        $con -> phone = $data['phone'];
        $con -> email = $data['email'];
        $con -> address = $data['address'];
        $con -> jwd = $data['jwd'];
        $result = $con -> save();
        if ($result){
            return 1;
        } else {
            return '更新失败！';
        }
    }

}
